/*
 *  $Id: ParticleEffect.cs 1191 2010-11-12 16:17:29Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using AgateLib.Geometry;

using Ragima.Helper;

namespace Ragima.UI {
    /// <summary>
    /// Интерфейс для эффекта воздействия на частицы.
    /// </summary>
    public interface IParticleEffect {
        void DoEffect(Particle part);
    }
}

namespace Ragima.UI.ParticleEffects {
    public abstract class Twirl : IParticleEffect {
        public abstract PointF GetCenter(Particle part);
        public abstract double GetAngleSpeed(Particle part);
        public abstract double GetRadiusSpeed(Particle part);

        #region IParticleEffect implementation
        public void DoEffect(Particle part) {
            var pos = part.Position;
            var center = GetCenter(part);
            var polar = pos.ToPolar(center);
            polar.ChangeBy(GetAngleSpeed(part), GetRadiusSpeed(part));
            var newPos = polar.ToPointF(center);
            var offset = newPos.Sub(pos);
            part.MoveBy(offset);
        }
        #endregion
    }

    public class ConstantTwirl : Twirl {
        private PointF _center;
        private double _speedAngle, _speedRadius;

        public ConstantTwirl(Point center, double speedAngle) : this(center.ToF(), speedAngle, 0) {
        }
        public ConstantTwirl(Point center, double speedAngle, double speedRadius) : this(center.ToF(), speedAngle, speedRadius) {
        }
        public ConstantTwirl(PointF center, double speedAngle) : this(center, speedAngle, 0) {
        }
        public ConstantTwirl(PointF center, double speedAngle, double speedRadius) {
            _center = center;
            _speedAngle = speedAngle;
            _speedRadius = speedRadius;
        }

        public override PointF GetCenter(Particle part) {
            return _center;
        }
        public override double GetAngleSpeed(Particle part) {
            return _speedAngle;
        }
        public override double GetRadiusSpeed(Particle part) {
            return _speedRadius;
        }
    }
}